package com.googlecode.maurersmarbles;

import java.util.ArrayList;
import java.util.List;

public class Player {

	/**
	 * The player number.
	 */
	protected final int playerNumber;
	/**
	 * The player's cards.
	 */
	protected final List<Card> cards = new ArrayList<Card>();
	/**
	 * The player's marbles.
	 */
	protected final Marble[] marbles;

	/**
	 * Creates a new Player.
	 * @param playerNumber playerNumber
	 */
	public Player(int playerNumber) {
		this.playerNumber = playerNumber;
		marbles = new Marble[GameLogic.MARBLES_PER_PLAYER];
		for (int i = 0; i < GameLogic.MARBLES_PER_PLAYER; i++) {
			marbles[i] = new Marble(playerNumber, i,
					Board.START_MIN[playerNumber] + i);
		}
	}

	/**
	 * Creates a new Player.
	 * @param player the player to copy
	 */
	public Player(Player player) {
		this(player.playerNumber);
		for (int i = 0; i < marbles.length; i++) {
			marbles[i].setBoardIndex(player.marbles[i].getBoardIndex());
		}
		cards.addAll(player.getCards());
	}

	/**
	 * Returns the player's cards.
	 * @return the player's cards
	 */
	public List<Card> getCards() {
		return cards;
	}

	/**
	 * Returns the marble with the given marble number.
	 * @param marble the marble number
	 * @return the marble with the given marble number
	 */
	public Marble getMarble(int marble) {
		return marbles[marble];
	}

	/**
	 * Returns the player's marbles.
	 * @return the player's marbles
	 */
	public Marble[] getMarbles() {
		return marbles;
	}

	/**
	 * Returns the player number.
	 * @return the player number
	 */
	public int getPlayerNumber() {
		return playerNumber;
	}

}
